package SimpleConnect;

import com.java.serverpackage.MessagePacket;
import java.io.*;
import java.net.*;

public class SimpleConnect{
    /********
     * Simple program to connect 
     * to a server.
     ********/
	
	Socket requestSocket;
	ObjectOutputStream out;
 	ObjectInputStream in;
 	String message;
	
	SimpleConnect(){}
	
	void run()
	{
		try{
			//1. creating a socket to connect to the server
			requestSocket = new Socket("85.224.21.254", 5163);
			System.out.println("Connected to 85.224.21.254 in port 5163");
			//2. get Input and Output streams
			out = new ObjectOutputStream(requestSocket.getOutputStream());
			out.flush();
			//out.writeObject(new MessagePacket(10,"Hello from SimpleConnect"));
			in = new ObjectInputStream(requestSocket.getInputStream());
			//3: Communicating with the server
			boolean bye = true;
			while(bye){
				Thread.sleep(2*1000);
				out.writeObject(new MessagePacket(0,"Hello from SimpleConnect_1"));
				Thread.sleep(2*1000);
				out.writeObject(new MessagePacket(0,"Hello from SimpleConnect_2"));
				Thread.sleep(2*1000);
				out.writeObject(new MessagePacket(0,"Hello from SimpleConnect_3"));
				Thread.sleep(2*1000);
				bye = false;
			}
			Thread.sleep(10*1000);
			requestSocket.close();
		} catch(Exception e){  }
	}
	
	public static void main(String args[]) {
		SimpleConnect client = new SimpleConnect();
		client.run();
	}
}